import React from "react";
import { View, Text } from "react-native";

import SizeUtils from "../../common/SizeUtils";
import CommonStyles from "../../common/CommonStyles";
import Config from "../../config";
import BasePage from "../common/BasePage";
import UserRequestAPPConfigAction from "../../actions/user/UserRequestAPPConfigAction";

export default class UserContactUsPage extends BasePage {
  constructor(props) {
    super(props);

    this.state.constactDatas = [];
  }

  _dealComponentWillUpdate(nextProps, nextState) {
    if (nextState.configSuccess === true) {
      //QQ群:647590221|客服电话:15045870336|客服QQ:1832515759|意见邮箱:ytgh_app@163.com
      nextState.constactDatas = nextState.configData.value.split("|");
    }
  }

  componentDidMount() {
    this._requestData();
  }

  _dealEnterPage() {
    super._dealEnterPage();
    this._requestData();
  }

  render() {
    return (
      <View
        style={[
          CommonStyles.page,
          {
            paddingTop:
              Config.paddingTop + SizeUtils.translateDesignHeightToCode(30),
            flex: 1,
            paddingLeft: SizeUtils.translateDesignWidthToCode(40),
            paddingRight: SizeUtils.translateDesignWidthToCode(40),
            backgroundColor: "#ffffff"
          }
        ]}
      >
        {this.state.constactDatas.map((data, index) => {
          return this._renderItem(data, index);
        })}
        {this._renderNavigationBar()}
      </View>
    );
  }

  _renderItem(data, index) {
    return (
      <View
        key={index}
        style={{
          height: SizeUtils.translateDesignHeightToCode(90),
          flexDirection: "row",
          alignItems: "center",
          borderColor: "#eeeeee",
          borderBottomWidth: SizeUtils.translateDesignNumToCode(3),
          paddingLeft: SizeUtils.translateDesignWidthToCode(28)
        }}
      >
        <Text
          style={{
            textAlign: "center",
            fontSize: SizeUtils.translateFontSizeToCode(28),
            color: "#000000"
          }}
        >
          {data}
        </Text>
      </View>
    );
  }

  _requestData() {
    new UserRequestAPPConfigAction().call(this, {
      key: "contact_us",
      requestType: "config"
    });
  }
}
